package a02;

public class AlphaBetaVierControl extends VierControl {

    private static final long serialVersionUID = 1L;
    private int depth = 14;
    private  GameAI<Byte> ai = new AlphaBetaGame<Byte>() {
	@Override
	public int getDepth() {
	    return depth;
	}
    };


    AlphaBetaVierControl() {
	this(new Vier());
    }

    AlphaBetaVierControl(Vier g) {
	super(g,14);
	setGameMode1Player(true);
    }


    
    public void setDepth(int depth) {
	this.depth = depth;
    }



    @Override
    public void whenMousePressed(byte c, byte r) {
	if (this.getBoard().getGame().ended()) {
	    return;
	}
	if (this.getBoard().getGame().currentPlayer() == this.getBoard().getGame()
		.getPlayerOne()) {
	    if (getStack().isEmpty())
		setDepth(getMenu().getSkillLevel());
	    super.whenMousePressed(c, r);
	} else {
	    this.getBoard().setGame((Vier) this.ai.doBestMove(this.getBoard().getGame()));
	    refresh();
	}
    }
    
    @Override
    public void refresh() {
	String status = "";
	boolean thinking = false;
	if (this.getBoard().getGame().currentPlayer() == AbstractRegularGame
		.getOne()) {
	    status = "Sie (Spieler "
		    + this.getBoard().getPlayerColorName(
			    this.getBoard().getGame().currentPlayer())
		    + ") sind an der Reihe";
	} else {
	    status = "Computer ist dran - bitte klicken!";
	    thinking=true;
	}

	getMenu().setStatus(status,thinking);
	System.out.println(".");
    }
}
